/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.siufung.core.model.enums.DeletedEnum;
import net.siufung.market.base.dict.mapper.IDictTypeMapper;
import net.siufung.market.base.dict.mapper.entity.Dict;
import net.siufung.market.base.dict.mapper.entity.DictType;
import net.siufung.market.base.dict.service.IDictService;
import net.siufung.market.base.dict.service.IDictTypeService;
import net.siufung.mybatis.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * 字典类型 数据服务实现
 *
 * @author 陈建峰
 * @since 2022-07-08 15:30:16
 */
@Slf4j
@AllArgsConstructor
@Service(value = "dictTypeService")
@Transactional(rollbackFor = Exception.class)
public class DictTypeServiceImpl extends BaseServiceImpl<IDictTypeMapper, DictType> implements IDictTypeService {

    private final IDictService dictService;

    @Override
    public boolean updateStatusById(Serializable id, DeletedEnum deletedEnum) {
        if(super.update(
                new LambdaUpdateWrapper<DictType>()
                        .eq(DictType::getId, id)
                        .set(DictType::getDeleted, deletedEnum.getValue()))){
            dictService.update(
                    new LambdaUpdateWrapper<Dict>()
                    .eq(Dict::getDictTypeId, id)
                    .set(Dict::getDeleted, deletedEnum.getValue()));
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}